﻿namespace LearnRouting.Models;

public class EmployeeRepository
{
    private static List<Employee> employees = new List<Employee>
    {
        new Employee(1, "John", "Engineer", 6000),
        new Employee(2, "Smith", "Manager", 5000),
        new Employee(3, "Sam", "Technician", 7000),
    };

    public static List<Employee> GetEmployees() => employees;

    public static Employee GetEmployeesById(int id)
    {
        return employees.FirstOrDefault(x => x.Id == id);
    }
    
    public static void AddEmployee(Employee? employee)
    {
        if (employee is not null)
        {
            employees.Add(employee);
        }
    }

    public static bool UpdateEmployee(Employee? employee)
    {
        if (employee is not null)
        {
            var emp = employees.FirstOrDefault(x => x.Id == employee.Id);
            if (emp is not null)
            {
                emp.Name = employee.Name;
                emp.Position = employee.Position;
                emp.Salary = employee.Salary;

                return true;
            }
        }

        return false;
    }

    public static bool DeleteEmployee(int Id)
    {
        var employee = employees.FirstOrDefault(x => x.Id == Id);
        if (employee is not null)
        {
            return true;
        }

        return false;
    }
}